package testcase.doctor;

import common.Host;
import common.TestData;
import common.doctor.Doctor;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.json.JSONException;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import api.doctor.GetAPIAccountInfoPC;
import api.doctor.UpdateStatus;


/**
 * 帮忙医医生端登录GetAPIAccountInfoPC接口测试用例
 * @author lyn
 */
public class TestGetAPIAccountInfoPC {
	/**
	 * 帮忙医医生端登录GetAPIAccountInfoPC接口测试环境数据驱动
	 * @return 测试数据
	 * @throws Exception
	 */
	@DataProvider (name = "Test")
	public static String[][] testGetAPIAccountInfoPCDataProvider() throws Exception
	{
		Host.setup("Test");
		TestData td = new TestData("doctor/TestGetAPIAccountInfoPC.xml");
		return td.getParam();	
	}
	
	/**
	 * 帮忙医医生端登录GetAPIAccountInfoPC接口
	 * @param caseName - 用例名称
	 * @param account - 医生账号
	 * @param password - 密码
	 * @return 接口返回数据
	 * @throws Exception
	 */
	@Test (dataProvider = "Test", groups = {"Test"})
	public void testGetAPIAccountInfoPCTestCase(String caseName, String account, String password) throws Exception
	{

		//调用接口并将接口返回数据转换成json格式
		
		String result = GetAPIAccountInfoPC.post(account,password);	
		JSONObject jsonResult;
		if (result==null || result.isEmpty())
		{
			jsonResult = null;
		}
		else
		{
			jsonResult = new JSONObject(result);
		}
		//设置检查点
		switch (caseName)
		{
		case "Success":
			Assert.assertEquals(jsonResult.getString("Loginstatus"), "Success");	//接口返回Loginstatus字段是否为Success
			break;
		case "PasswordError":
			Assert.assertEquals(jsonResult.getString("Message"), "密码错误");	//接口返回Message字段是否为"密码错误"
			break;
		case "AsswordError":
			Assert.assertEquals(jsonResult.getString("Message"), "用户不存在，请联系系统管理员");	//接口返回Message字段是否为"用户不存在，请联系系统管理员"
			break;
		case "Nopassword":
			Assert.assertEquals(jsonResult.getString("Message"), "密码错误");	//接口返回Message字段是否为"密码错误"
			break;
		case "Noaccount":
			Assert.assertEquals(jsonResult.getString("Message"), "用户不存在，请联系系统管理员");	//接口返回Message字段是否为"用户不存在，请联系系统管理员"
			break;
		}

	}
	// 登录后下线
	@AfterTest(groups = "Test")
	public void afterTest() throws JSONException, IOException, ParserConfigurationException, SAXException
	{
		Host.setup("Test");
		TestData tData=new TestData("doctor/TestGetAPIAccountInfoPC.xml");
		String account=tData.getData("Success", "account");
		String password=tData.getData("Success", "password");
		Doctor doctor=new Doctor(account, password);
		UpdateStatus.put("False", "1",  String.valueOf(doctor.id), doctor.token);		
	}
	}
